//
//  MyTableViewController.m
//  bitcoin
//
//  Created by caiyajun on 2018/5/8.
//  Copyright © 2018年 比特币. All rights reserved.
//

#import "MyTableViewController.h"
#import "LoginView.h"
#import "OneselfCentreViewController.h"
#import "MyOrderViewController.h"

#import "MyInviteTableViewController.h"
@interface MyTableViewController ()
@property (nonatomic, strong) LoginView *loginView;
- (IBAction)clickSetAction:(id)sender;
@property (weak, nonatomic) IBOutlet UILabel *phoneLabel;
@property (weak, nonatomic) IBOutlet UILabel *udidLabel;
@property (nonatomic, strong) NSString *status;

@property (nonatomic, strong) NSString *useId;
@end

@implementation MyTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.phoneLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:13];
    
    
    
    
    
    

}
-(void)viewWillAppear:(BOOL)animated{
    if (![UserDefaults objectForKey:K_LOGININFO_TOKEN]) {
        LoginView *loginView = [LoginView xib];
        self.loginView=loginView;
        [[UIApplication sharedApplication].keyWindow addSubview:loginView];
        loginView.loginActionBlock = ^(NSString*text) {
            
            //弹出登录页面
            BaseNavigationController *base = [[UIStoryboard storyboardWithName:@"Login" bundle:nil] instantiateInitialViewController];
            [self presentViewController:base animated:NO completion:nil];
            //        [weakLoginView removeFromSuperview];
        };
    }
    
    
    
    
    
    [LSRequestManager getRequestWithURL:HUOBI(@"api/user/info")
                                 params:nil
                                success:^(NSDictionary *responseData) {
                                    if ([responseData[@"ret"] integerValue ] == 0) {
                                        NSString*phoneStr;
                                        phoneStr=[NSString stringWithFormat:@"%@",responseData[@"data"][@"email"]];
                                        NSMutableString *phoneStr1 = [NSMutableString stringWithString:phoneStr];
                                        if (phoneStr.length>4) {
                                            [phoneStr1 replaceCharactersInRange:NSMakeRange(0, 4) withString:@"****"];
                                        }
                                        self.phoneLabel.text=phoneStr1;
                                        self.udidLabel.text=[NSString stringWithFormat:@"%@",responseData[@"data"][@"user_no"]];
                                        self.status=[NSString stringWithFormat:@"%@",responseData[@"data"][@"user_auth"][@"status"]];
                                        
                                        self.useId=[NSString stringWithFormat:@"%@",responseData[@"data"][@"id"]];
                                        
                                    } else {
                                        self.phoneLabel.text=@"";
                                        self.udidLabel.text=@"";
                                    }
                                }
                                failure:^(NSError *error) {
                                    self.phoneLabel.text=@"";
                                    self.udidLabel.text=@"";
                                }
                                showHUD:NO];
}



-(void)viewWillDisappear:(BOOL)animated{
    if (self.loginView) {
        [self.loginView removeFromSuperview];
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return 7;
}
-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath{
    if (indexPath.row==0) {
        
        [self performSegueWithIdentifier:@"accountCapitalSegue" sender:nil];
    }else if (indexPath.row==1){
        [self performSegueWithIdentifier:@"drawAddressSegue" sender:nil];
        
    }else if (indexPath.row==2){
        MyOrderViewController *order = [[MyOrderViewController alloc]init];
        [self.navigationController pushViewController:order animated:YES];
        //        BaseNavigationController *base = [[UIStoryboard storyboardWithName:@"Login" bundle:nil] instantiateInitialViewController];
        //        [self presentViewController:base animated:NO completion:nil];

        
    }else if (indexPath.row==3){
        [self performSegueWithIdentifier:@"oneselfCentreSegue" sender:nil];
    }else if (indexPath.row==4){
        
        [self performSegueWithIdentifier:@"myInviteSegue" sender:nil];
    }else if (indexPath.row==5){
        
        [self performSegueWithIdentifier:@"moreCertifySegue" sender:nil];
    }else if (indexPath.row==6){
        [self performSegueWithIdentifier:@"aboutSegue" sender:nil];
    }
    
    
}


- (IBAction)clickSetAction:(id)sender {
    [self performSegueWithIdentifier:@"settingSegue" sender:nil];
    

//    BaseNavigationController *base = [[UIStoryboard storyboardWithName:@"Login" bundle:nil] instantiateInitialViewController];
//    [self presentViewController:base animated:NO completion:nil];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"oneselfCentreSegue"]) {
        OneselfCentreViewController *oneselfCode = segue.destinationViewController;
        oneselfCode.phone = self.phoneLabel.text;
        oneselfCode.udid = self.udidLabel.text;
        oneselfCode.status = self.status;
    }else if ([segue.identifier isEqualToString:@"myInviteSegue"]){
        MyInviteTableViewController *myInviteTV = segue.destinationViewController;
        myInviteTV.useId = self.useId;
        
    }
}
@end
